package com.pureut.system.controller;

import cn.hutool.core.io.resource.InputStreamResource;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.pureut.common.core.domain.R;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.RepairFileManagement;
import com.pureut.system.domain.dto.SupplierListPageDto;
import com.pureut.system.domain.vo.RepairFileManagementVo;
import com.pureut.system.domain.vo.SupplierListVo;
import com.pureut.system.service.RepairFileManagementService;
import com.pureut.system.util.ExcelUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.util.List;

/**
 * @ClassName RepairFileManagementController
 * @Description: 维修文件管理控制层
 * @Author: try
 * @CreateDate: 2025/4/11 14:58	//创建时间
 * @UpdateUser: try
 * @UpdateDate: 2025/4/11 14:58	//更新时间
 * @UpdateRemark: 更新的信息
 * @Version: 1.0    //版本号
 */
@RestController
@RequestMapping("/repairFileManagement")
public class RepairFileManagementController extends BaseController
{

    @Resource
    RepairFileManagementService repairFileManagementService;


    /**
     * 列表
     */
    @GetMapping("/getList")
    public TableDataInfo getList(RepairFileManagementVo repairFileManagement){
        startPage();
        return getDataTable(repairFileManagementService.getLit(repairFileManagement));
    }


    /**
     * 上传
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody RepairFileManagementVo repairFileManagement) throws Exception
    {
        return toAjax(repairFileManagementService.add(repairFileManagement));
    }

    /**
     * 查看
     */
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") String id){
        return AjaxResult.success(repairFileManagementService.view(id));
    }

    /**
     * 删除
     */
    @DeleteMapping("/removeBeach")
    public AjaxResult deleteBeach(@RequestBody RepairFileManagement repairFileManagement){
        return toAjax(repairFileManagementService.deleteBeach(repairFileManagement.getIds()));
    }

    /**
     * 修改
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody RepairFileManagementVo repairFileManagement){
        return toAjax(repairFileManagementService.edit(repairFileManagement));
    }

    /**
     * 维修文件管理导出
     */
    @PostMapping("/export")
    public AjaxResult export(HttpServletResponse response, RepairFileManagementVo repairFileManagement) throws IOException
    {
        List<RepairFileManagement> infoExport = repairFileManagementService.getInfoExport(repairFileManagement);
        ExcelUtil<RepairFileManagement> excelUtil = new ExcelUtil<RepairFileManagement>(RepairFileManagement.class);
        excelUtil.excelWriter(response, infoExport, "维修文件管理.xlsx");
        return AjaxResult.success();
    }

}